﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eProject_SEM3_SecurityServices.Bussiness;
using eProject_SEM3_SecurityServices.ObjectClass;

namespace eProject_SEM3_SecurityServices
{
    public partial class WebForm6 : System.Web.UI.Page
    {
        BCustomer bc = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            bc = new BCustomer();
            if (!IsPostBack)
            {
                DataBindCustomer();
            }
        }

        public void DataBindCustomer()
        {
            GridView1.DataSource = bc.getCustomerList();
            GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            OCustomer customer = new OCustomer();
            customer.CustomerName = txtName.Text;
            customer.CustomerAddress = txtAddress.Text;
            customer.CustomerPhone = txtPhone.Text;
            bc.AddCustomer(customer);
            DataBindCustomer();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName != String.Empty)
            {
                int index = Convert.ToInt32(e.CommandArgument);

                switch (e.CommandName.ToString())
                {
                    case "AddContract":
                        AddContractOrder(index);
                        DataBindCustomer();
                        break;                   
                }
            }
        }

        public void AddContractOrder(int index)
        {
            int customerID = Convert.ToInt32(GridView1.Rows[index].Cells[0].Text);
            Response.Redirect("frmManagerContract.aspx?id=" + customerID);
        }
    }
}